package test.quna;

import java.util.ArrayList;
import java.util.List;

/**
 * @description: 去哪旅行笔试，编程比较简单AK
 * @author: w_jingbo
 * @date: 2023/9/15
 * @Copyright: 博客：http://coisini.wang
 */
public class Main {

    public static void main(String[] args) {
        int[] arr = new int[]{1,2,4,4,5} ;
        int n = arr.length ;
        find(n,0,arr);
    }

    public static int find (int n, int v, int[] a) {
        // write code here
        if(a[0] == v){
            return 1;
        }
        int left = 0 ;
        int right = n-1 ;
        int res = -1 ;
        while(left <= right){
            int mid = left + (right - left) / 2;
            if(a[mid] == v){
                right = mid - 1 ;
                res = mid ;
            }else if(a[mid] < v){
                left = mid + 1;
            }else {
                right = mid - 1;
            }
        }

        System.out.println(res);
        if(res == -1 ){
            return a.length + 1 ;
        }
        return res+1;
    }

    public static int[] findQ (int n, int[] nums) {
        // write code here
        List<Integer> list = new ArrayList<>();
        for (int i = n-1; i >= 0; i--) {
            if(list.contains(nums[i])){
                continue;
            }
            list.add(nums[i]) ;
        }
        int[] arr = new int[list.size()] ;
        for (int i = 0; i < list.size(); i++) {
            arr[i] = list.get(list.size()-1-i) ;
        }
        return arr;
    }
}
